package run.theo.mallorder.feign.fallback;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import run.theo.mallcommons.entity.Product;
import run.theo.mallorder.feign.ProductsProvider;

/**
 * project name: IntelliJ IDEA
 * Date: 2022/10/18 19:14
 *
 * @PackageName: run.theo.mallorder.service.fallback
 * @ClassName: ProductsProviderFallback
 * @Author: Theo
 * @Version:
 * @Description: 这是容错类，他要求我们要实现一个接口，接口中的泛型是要为哪个远程调用接口产生容错类
 */
@Component
@Slf4j
public class ProductsProviderFallback implements FallbackFactory<ProductsProvider> {
    @Override
    public ProductsProvider create(Throwable throwable) {

        return new ProductsProvider() {
            @Override
            public Product findByPid(Integer pid) {
                log.error("{}",throwable);
                Product product = new Product();
                product.setPid(-1);
                product.setPname("商品微服务调用出现异常了，已经进入到了容错方法");
                return product;
            }
        };
    }
}
